<?php
/**
 * file_get_contents的post请求
 * request.php
 * reponse.php
 **/ 
//json会报错
$bodyType = 'json'; //json x-www-form-urlencoded text/html
$data = array("name" => 'tim',"content" => 'test'); 
if ('json' == $bodyType) {
    $data = json_encode($data, 256);
} else {
    $data = http_build_query($data);
}
$data ='{"event":"callhangup","callid":"1f6e39bcf2f0d1766e8ed78d580fcef7","accountid":"cc6f16f06dbbcbab6ace85f0df8cce0a","appid":"3f68c4a2d8a04f4f9ac23ade50b11c88","calltype":"2","lengthA":"84","callerdisnum":[],"calleedisnum":[],"callertype":"0","callernum":"18639579611","caller":"64422070657763","calledtype":"1","called":"15910543558","length":"71","calltime":"2017-03-22 15:42:33","starttime":"2017-03-22 15:42:52","stoptime":"2017-03-22 15:44:03","reason":"0","subreason":"2"}';
//var_dump(json_decode($data));
//$header = "Content-type: application/x-www-form-urlencoded\r\n". "Content-length:".strlen($data)."\r\n" . "Cookie: foo=bar\r\n" . "Appkey: jiangyongpd\r\n";
$header = array(
    "Content-type: application/x-www-form-urlencoded;charset=utf-8",
//    "Accept:application/$bodyType",
//   "Content-Type:application/$bodyType;charset=utf-8",
    "Content-length:".strlen($data),
//    "Cookie: foo=bar",
//    'Appkey: jiangyongpwd'
);
 $opts = array( 
    'http'=>array(
        'method'=>"POST",
        'timeout'=> 2,
        'header'=> $header , 
        'content' => $data,
        
    )
); 
 $cxContext = stream_context_create($opts);
 $sFile = file_get_contents("http://localhost/phponly/url/response.php", false, $cxContext);
//var_dump($http_response_header);
echo $sFile;
